<!DOCTYPE html>
<html>
<head>
<#include "/admin/common/common.ftl" parse=true encoding="utf-8">
<link href="${base}/scripts/ckeditor/skins/moono/editor.css" type="text/css" rel="stylesheet">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<#include "/admin/common/header.ftl" parse=true encoding="utf-8">

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>课程管理</h1>
				<ol class="breadcrumb">
					<li class="active">添加新课程</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!-- Info boxes -->
				<div class="row">
					<div class="box">
						<div class="box-header">
							<div class="table-btn">
								<a href="${base}/admin/template/mail/list.do">
									<span class="label label-primary">列表</span>
								</a>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
						<form class="form-horizontal" id="defaultForm" method="post" action="${base}/admin/course/addnewAction.do" enctype="multipart/form-data">
								<div class="form-group">
									<label class="col-md-2 control-label">课程图片</label>
									<div class="col-md-8">
										<img id="picUrl" class="img-thumbnail" width="150" height="100" />
										<input id="picUrlFile" name="files" type="file" style="display: none;" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">课程级别</label>
									<div class="col-md-8">
										<select id="level" name="level">
											<option value="1">初级</option>
											<option value="2">中级</option>
											<option value="3">高级</option>
											<option value="4">专家</option>
											<option value="5">首席</option>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">课程分类</label>
									<div class="col-md-8">
										<select id="catalogId" name="catalogId">
											<option value="1">JavaWeb</option>
											<option value="2">Android</option>
											<option value="3">IOS</option>
											<option value="4">PHP</option>
											<option value="5">Javascript</option>
											<option value="6">ASP</option>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">课程名称</label>
									<div class="col-md-8">
										<input id="name" name="name" class="form-control" type="text" rows="10" placeholder="请输入课程名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">讲师名称</label>
									<div class="col-md-8">
										<input id="speakerName" name="speakerName" class="form-control" type="text" rows="10" placeholder="请输入讲师名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">课程费用</label>
									<div class="col-md-8">
										<input id="totalPrice" name="totalPrice" class="form-control" type="text" rows="10" placeholder="请输入课程费用">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">课程简介</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="intro" placeholder="请输入课程简介" name="intro"></textarea>
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-offset-3 col-sm-3">
										<button type="submit" class="btn btn-primary">添加</button>
										<button type="submit" class="btn btn-primary"   onclick="returnList()">返回</button>
									</div>
								</div>
							</form>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
				<!-- /.row -->
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

	</div>
	<!-- ./wrapper -->
	<#include "/admin/common/footer.ftl" parse=true encoding="utf-8">
</body>
<script src="${base}/scripts/common/imgphoto.js"></script>
<script type="text/javascript">


	$(function() {

		$("#picUrlFile").uploadPreview({
			Img : "picUrl",
			Width : 160,
			Height : 90,
			Callback : function(data) {
				if (data)
					$("#picUrlFile").val('true');
			}
		});

		$("#picUrlFile").attr('src', "${base}/styles/images/common/default-avatar.png");
		
		var introEditor = null;
		introEditor = CKEDITOR.replace('intro');

	})

	function getValue(obj) {
		var value = $(obj).val();
		var reg = /.+(.JPEG|.jpeg|.JPG|.jpg)$/;
		if (reg.test(value)) {
			$(obj).next().val(value);
			$(obj).next().blur();
		}
	}

	$("#picUrl").click(function() {
		return document.getElementById("picUrlFile").click();
	});

		
		$('#defaultForm')
				.bootstrapValidator(
						{
							message : '该项不能为空',
							live : 'disabled',
							feedbackIcons : {
								valid : 'glyphicon glyphicon-ok',
								invalid : 'glyphicon glyphicon-remove',
								validating : 'glyphicon glyphicon-refresh'
							},
							
							submitHandler : function(validator, form, submitButton){
								if (window.confirm("确定要添加新课程？")) {
									validator.defaultSubmit();	
								} else{
									return;
								}
					            
				            },
							fields : {
								name : {
									validators : {
										notEmpty : {
											message : '课程名称不能为空'
										}
									}
								},
								speakerName : {
									validators : {
										notEmpty : {
											message : '讲师名称不能为空'
										}
									}
								},
								totalPrice : {
									validators : {
										notEmpty : {
											message : '课程费用不能为空'
										},
										numeric:{
											message : '请输入正确金额'
										}
									}
								},
								intro : {
									validators : {
										notEmpty : {
											message : '课程简介不能为空'
										}
									}
								},
								catalogId: {
									validators : {
										notEmpty : {
											message : '请选择课程类别'
										}
									}
								},
								level: {
									validators : {
										notEmpty : {
											message : '请选择课程级别'
										}
									}
								}
							}
						});
	
	
	function returnList(){
		window.location.href = "${base}/admin/course/list.do";
	}
</script>
</html>